package com.xbh.zzzTest;

import com.jfinal.json.FastJson;
import com.jfinal.kit.Ret;

/**
 * <p>
 * 继承Ret 重写状态
 * </p>
 *
 * @author: ZBoHang
 * @time: 2021/8/4 8:57
 */
public class RetTest extends Ret {

    public static RetTest me = new RetTest();

    private RetTest() {}

    public Ret nullControllerPath() {
        return me.setNullControllerPath();
    }

    public Ret nullAuth() {
        return me.setNullAuth();
    }

    public Ret errorAuth() {
        return me.setErrorAuth();
    }

    public Ret success(String msg) {
        return me.setSuccess(msg);
    }

    public Ret success(String msg, Object bean) {
        return me.setSuccess(msg, bean);
    }


    @Override
    public Ret setOk() {
        super.put("state", "200");
        return this;
    }

    @Override
    public Ret setFail() {
        super.put("state", "500");
        return this;
    }

    public Ret setFail(String msg) {
        super.put("state", "500");
        super.put("msg", msg);
        return this;
    }

    public Ret setNullControllerPath() {
        super.put("state", "404");
        super.put("msg", "未找到路径!");
        return this;
    }

    public Ret setNullAuth() {
        super.put("state", "401");
        super.put("msg", "没有token!");
        return this;
    }

    public Ret setErrorAuth() {
        super.put("state", "400");
        super.put("msg", "token不正确!");
        return this;
    }

    public Ret setSuccess(String msg) {
        super.put("state", "200");
        super.put("msg", msg);
        return this;
    }

    public Ret setSuccess(String msg, Object bean) {
        super.put("state", "200");
        super.put("msg", msg);
        super.put("bean", FastJson.getJson().toJson(bean));
        return this;
    }
}
